/**
 * Copyright 2005 The Apache Software Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.edi.runtime.component
{
	import flash.events.MouseEvent;
	
	import mx.collections.ListCollectionView;
	import mx.controls.MenuBar;
	import mx.events.MenuEvent;
	/**
	 * 本类已被淘汰
	 * 
	 */
	public class EDIToolBar extends MenuBar
	{
		private var arr:Array
		private var oldIndex:int=-1;
		
		public function EDIToolBar()
		{
			super();
			arr=new Array();
			dataProvider=arr;
			labelField="lab";
			this.addEventListener(MenuEvent.CHANGE,changeHandler);
			this.addEventListener(MouseEvent.MOUSE_UP,moseUpHandler);
			this.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler);
			this.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
		}

		public function addButton(label:String,mouseClickHandler:Function,width:int=100):void
		{
			var obj:Object=new Object();
			obj["lab"]=label;
			obj["fun"]=mouseClickHandler;
			arr.push(obj);
			(this.dataProvider as ListCollectionView).refresh();
		}
		
		protected function mouseMoveHandler(event:MouseEvent):void
		{
			oldIndex=-1;
		}
		
		protected function moseUpHandler(event:MouseEvent):void
		{
			oldIndex=-1;
		}
		
		protected function mouseDownHandler(event:MouseEvent):void
		{
			if(oldIndex!=-1)
			{
				var fun:Function=arr[oldIndex]["fun"]
				fun.call();
			}
		}
		
		protected function changeHandler(event:MenuEvent):void
		{
			if(oldIndex!=selectedIndex)
			{
				oldIndex=selectedIndex;
			}
		}
	}
}